{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "[![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/py-pdf/fpdf2/blob/master/tutorial/notebook.ipynb) <hr> [![Open In nbviewer](https://img.shields.io/badge/Open_In-nbviewer-blue?logo=jupyter)](https://nbviewer.org/github/py-pdf/fpdf2/blob/master/tutorial/notebook.ipynb)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Hello World with fpdf2\n",
    "This [Jupyter notebook](https://jupyter.org/) demontrates some basic usage of the Python [fpdf2](https://github.com/py-pdf/fpdf2) library"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": []
    }
   ],
   "source": [
    "# Installation of fpdf2 with PIP:\n",
    "!pip install fpdf2"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "# Enable deprecation warnings:\n",
    "import warnings\n",
    "warnings.simplefilter('default', DeprecationWarning)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "# Generate a PDF:\n",
    "from fpdf import FPDF\n",
    "pdf = FPDF()\n",
    "pdf.add_page()\n",
    "pdf.set_font('helvetica', size=48)\n",
    "pdf.cell(text=\"hello world\")\n",
    "pdf_bytes = pdf.output()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<embed src=\"data:application/pdf;base64,JVBERi0xLjMKMyAwIG9iago8PC9UeXBlIC9QYWdlCi9QYXJlbnQgMSAwIFIKL1Jlc291cmNlcyAyIDAgUgovQ29udGVudHMgNCAwIFI+PgplbmRvYmoKNCAwIG9iago8PC9GaWx0ZXIgL0ZsYXRlRGVjb2RlIC9MZW5ndGggNzM+PgpzdHJlYW0KeJwzUvDiMtAzNVco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kU5QjgyRkI0OEE3MTM0QjJFQzgwMTU5Pl0KPj4Kc3RhcnR4cmVmCjY3OQolJUVPRgo=\" width=\"800\" height=\"400\" type=\"application/pdf\">"
      ],
      "text/plain": [
       "<IPython.core.display.HTML object>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "# Display the PDF in the notebook by embedding it as HTML content:\n",
    "WIDTH, HEIGHT = 800, 400 \n",
    "from base64 import b64encode\n",
    "from IPython.display import display, HTML\n",
    "base64_pdf = b64encode(pdf_bytes).decode(\"utf-8\")\n",
    "display(HTML(f'<embed src=\"data:application/pdf;base64,{base64_pdf}\" width=\"{WIDTH}\" height=\"{HEIGHT}\" type=\"application/pdf\">'))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<a download=\"fpdf2-demo.pdf\" href=\"data:application/pdf;base64,JVBERi0xLjMKMyAwIG9iago8PC9UeXBlIC9QYWdlCi9QYXJlbnQgMSAwIFIKL1Jlc291cmNlcyAyIDAgUgovQ29udGVudHMgNCAwIFI+PgplbmRvYmoKNCAwIG9iago8PC9GaWx0ZXIgL0ZsYXRlRGVjb2RlIC9MZW5ndGggNzM+PgpzdHJlYW0KeJwzUvDiMtAzNVco53IKUdB3M1QwsdAzMFAISVNwDQEJGRvqGVoomJub6hmaKISkKGhkpObk5CuU5xflpGgqhGSBlAEAC64QcgplbmRzdHJlYW0KZW5kb2JqCjEgMCBvYmoKPDwvVHlwZSAvUGFnZXMKL0tpZHMgWzMgMCBSXQovQ291bnQgMQovTWVkaWFCb3ggWzAgMCA1OTUuMjggODQxLjg5XQo+PgplbmRvYmoKNSAwIG9iago8PC9UeXBlIC9Gb250Ci9CYXNlRm9udCAvSGVsdmV0aWNhCi9TdWJ0eXBlIC9UeXBlMQovRW5jb2RpbmcgL1dpbkFuc2lFbmNvZGluZwo+PgplbmRvYmoKMiAwIG9iago8PAovUHJvY1NldCBbL1BERiAvVGV4dCAvSW1hZ2VCIC9JbWFnZUMgL0ltYWdlSV0KL0ZvbnQgPDwKL0YxIDUgMCBSCj4+Ci9YT2JqZWN0IDw8Cj4+Cj4+CmVuZG9iago2IDAgb2JqCjw8Ci9DcmVhdGlvbkRhdGUgKEQ6MjAyMjA5MTUwNjU0NDJaMDYnNTQnKQo+PgplbmRvYmoKNyAwIG9iago8PAovVHlwZSAvQ2F0YWxvZwovUGFnZXMgMSAwIFIKL09wZW5BY3Rpb24gWzMgMCBSIC9GaXRIIG51bGxdCi9QYWdlTGF5b3V0IC9PbmVDb2x1bW4KPj4KZW5kb2JqCnhyZWYKMCA4CjAwMDAwMDAwMDAgNjU1MzUgZiAKMDAwMDAwMDIyOSAwMDAwMCBuIAowMDAwMDAwNDExIDAwMDAwIG4gCjAwMDAwMDAwMDkgMDAwMDAgbiAKMDAwMDAwMDA4NyAwMDAwMCBuIAowMDAwMDAwMzE1IDAwMDAwIG4gCjAwMDAwMDA1MTUgMDAwMDAgbiAKMDAwMDAwMDU3NiAwMDAwMCBuIAp0cmFpbGVyCjw8Ci9TaXplIDgKL1Jvb3QgNyAwIFIKL0luZm8gNiAwIFIKL0lEIFs8NEU0Nzc0MTZCRTlCODJGQjQ4QTcxMzRCMkVDODAxNTk+PDRFNDc3NDE2QkU5QjgyRkI0OEE3MTM0QjJFQzgwMTU5Pl0KPj4Kc3RhcnR4cmVmCjY3OQolJUVPRgo=\">Click to download PDF</a>"
      ],
      "text/plain": [
       "<IPython.core.display.HTML object>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "# Diplay a download button:\n",
    "display(HTML(f'<a download=\"fpdf2-demo.pdf\" href=\"data:application/pdf;base64,{base64_pdf}\">Click to download PDF</a>'))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "To continue learning about `fpdf2`, check our tutorial:\n",
    "- [English](https://py-pdf.github.io/fpdf2/Tutorial.html)\n",
    "- [Deutsch](https://py-pdf.github.io/fpdf2/Tutorial-de.html)\n",
    "- [español](https://py-pdf.github.io/fpdf2/Tutorial-es.html)\n",
    "- [हिंदी](https://py-pdf.github.io/fpdf2/Tutorial-हिंदी.html)\n",
    "- [português](https://py-pdf.github.io/fpdf2/Tutorial-pt.html)\n",
    "- [Русский](https://py-pdf.github.io/fpdf2/Tutorial-ru.html)\n",
    "- [Italian](https://py-pdf.github.io/fpdf2/Tutorial-it.html)\n",
    "- [français](https://py-pdf.github.io/fpdf2/Tutorial-fr.html)\n",
    "- [Ελληνικά](https://py-pdf.github.io/fpdf2/Tutorial-gr.html)\n",
    "- [עברית](https://py-pdf.github.io/fpdf2/Tutorial-he.html)\n",
    "- [Dutch](https://py-pdf.github.io/fpdf2/Tutorial-nl.html)"
   ]
  }
 ],
 "metadata": {
  "colab": {
   "collapsed_sections": [],
   "include_colab_link": true,
   "name": "Hello World with fpdf2",
   "provenance": []
  },
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.10"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 1
}
